"use strict";
Object.defineProperty(exports, "__esModule", {
  value: true
});

function formatTime(date) {
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var day = date.getDate();
  var hour = date.getHours();
  var minute = date.getMinutes();
  var second = date.getSeconds();
  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':');
}

var formatNumber = function(n) {
  var str = n.toString();
  return str[1] ? str : '0' + str;
};

//navigate to page
function gotoPage(event, page, back) {
  var page = page || event.currentTarget.dataset.page;
  var pages = {    
    "home": "/pages/home/home",
    "buy": "/pages/buy/buy",
    "tuanorder": "/pages/tuan/tuanorder/tuanorder",
    "tuanlist": "/pages/tuan/tuanlist/tuanlist",
    "cashapply": "/pages/tuan/cashapply/cashapply",
    "cashhistory": "/pages/tuan/cashhistory/cashhistory",
    "myorder": "/pages/usercenter/myorder/myorder",
    "mytuan": "/pages/usercenter/mytuan/mytuan",
    "help": "/pages/usercenter/help/help",
    "userinfo": "/pages/usercenter/userinfo/userinfo",
    "addresslist": "/pages/usercenter/addresslist/addresslist",
    "addressnew": "/pages/usercenter/addressnew/addressnew",
    "usermenu": "/pages/usercenter/usermenu/usermenu",
    "starttuan": "/pages/tuan/starttuan/starttuan",
    "starttuanok": "/pages/tuan/starttuanok/starttuanok",
    "applyatuanok": "/pages/usercenter/applyatuanok/applyatuanok",
    "applyatuan": "/pages/usercenter/applyatuan/applyatuan",
  };
  var tabBars = {
    "index": "/pages/index/index",
    "applyat": "/pages/usercenter/applyat/applyat",
    "menu": "/pages/usercenter/menu/menu",
  }
  console.log(page);
  if (tabBars[page]) {
    wx.switchTab({
      url: tabBars[page],
    })
    wx.showTabBar({});
  } else {
    var url = pages[page] || pages['index'];
    console.log(url);
    if (back) {
      wx.navigateBack({
        url: url,
      })({
        url: url
      });
    } else {
      wx.navigateTo({
        url: url
      });
    }

    wx.hideTabBar({});
  }
}

exports.gotoPage = gotoPage;
exports.formatTime = formatTime;